package com.ikas.ai.server.module.system.controller;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.handle.JsonResultType;
import com.ikas.ai.server.module.AbstractBean;
import com.ikas.ai.server.module.system.model.Permission;
import com.ikas.ai.server.module.system.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * 系统管理-菜单管理
 *
 * @author lhn
 */
@RestController
@RequestMapping("/home/menu")
public class MenuController extends AbstractBean {

    @Autowired
    private PermissionService permissionService;

    /**
     * 获取资源.
     *
     * @return
     */
    @GetMapping(value = "/getResource")
    public String getResource() {
        JsonResult jsonResult = new JsonResult(JsonResultType.OK);
        //用户账号
        String userName = this.getUserName();
        //获取用户菜单权限
        Set<Permission> menuList = permissionService.getResource(userName);
        //获取用户操作权限
        Set<String> permissions = permissionService.getUserPermissions(getUser());
        jsonResult.add("menuList", menuList);
        jsonResult.add("permissions", permissions);
        return jsonResult.toJSON();
    }

}
